package WebClick.app;

import static org.junit.Assert.fail;

import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.concurrent.TimeUnit;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.NoAlertPresentException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;


import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*; 


import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters; 
import java.util.Arrays;
import java.util.Collection; 




@RunWith(Parameterized.class)
public class App {
	
	
	private String h;
	private String w;
	private String ans;
	
	@Parameters
	public static Collection data(){
		return Arrays.asList(new Object[][]{
			{"159", "60", "24"},
			{"180", "60", "19"},
			{"190", "60", "17"}
		});
	}
	public App(String a,String b,String c){
		this.h = a;
		this.w = b;
		this.ans = c;
	}
	
	
	
	
	
  private WebDriver driver;
  private String baseUrl;
  private boolean acceptNextAlert = true;
  private StringBuffer verificationErrors = new StringBuffer();

  @Before
  public void setUp() throws Exception {
	System.setProperty("webdriver.firefox.bin", "D:\\FireFox\\firefox.exe");
	System.setProperty("webdriver.gecko.driver", "D:\\python3.4.4\\geckodriver\\geckodriver.exe");
	driver = new FirefoxDriver();
    baseUrl = "http://cn.onlinebmicalculator.com/";
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
  }

  @Test
  public void testAass() throws Exception {
    driver.get(baseUrl + "/");
    driver.findElement(By.name("f_height")).clear();
    driver.findElement(By.name("f_height")).sendKeys(h);
    driver.findElement(By.name("f_weight")).clear();
    driver.findElement(By.name("f_weight")).sendKeys(w);
    driver.findElement(By.id("bt")).click();
    driver.findElement(By.name("f_submit")).click();
    driver.findElement(By.name("f_height")).clear();
    driver.findElement(By.name("f_height")).sendKeys(h);
    driver.findElement(By.name("f_weight")).clear();
    driver.findElement(By.name("f_weight")).sendKeys(w);
    driver.findElement(By.name("f_submit")).click();
  }
  
  @Test
  public void testAassplus() throws Exception {
    driver.get(baseUrl + "/");
    driver.findElement(By.name("f_height")).clear();
    driver.findElement(By.name("f_height")).sendKeys(w);
    driver.findElement(By.name("f_weight")).clear();
    driver.findElement(By.name("f_weight")).sendKeys(h);
    driver.findElement(By.id("bt")).click();
    driver.findElement(By.name("f_submit")).click();
    driver.findElement(By.name("f_height")).clear();
    driver.findElement(By.name("f_height")).sendKeys(w);
    driver.findElement(By.name("f_weight")).clear();
    driver.findElement(By.name("f_weight")).sendKeys(h);
    driver.findElement(By.name("f_submit")).click();
  }
  
  

  @After
  public void tearDown() throws Exception {
    driver.quit();
    String verificationErrorString = verificationErrors.toString();
    if (!"".equals(verificationErrorString)) {
      fail(verificationErrorString);
    }
  }

  private boolean isElementPresent(By by) {
    try {
      driver.findElement(by);
      return true;
    } catch (NoSuchElementException e) {
      return false;
    }
  }

  private boolean isAlertPresent() {
    try {
      driver.switchTo().alert();
      return true;
    } catch (NoAlertPresentException e) {
      return false;
    }
  }

  private String closeAlertAndGetItsText() {
    try {
      Alert alert = driver.switchTo().alert();
      String alertText = alert.getText();
      if (acceptNextAlert) {
        alert.accept();
      } else {
        alert.dismiss();
      }
      return alertText;
    } finally {
      acceptNextAlert = true;
    }
  }
  
  
  
  	
	
  
  
}
